//
//  CommonToolsViewController.m
//  Rong360
//
//  Created by tianliwei on 7/2/14.
//  Copyright (c) 2014 tianliwei. All rights reserved.
//

#import "CommonToolsViewController.h"
#import "ComToolCell.h"
#import "RealEstateQaViewController.h"
#import "LoanCalculatorViewController.h"
#import "EvaluateCalculatorViewController.h"
#import "TaxesCalculatorViewController.h"
#import "PrepaymentCalculatorViewController.h"
#import "RemainPaymentCalculatorViewController.h"
@interface CommonToolsViewController ()
@property (nonatomic, strong)NSArray *titles;
@property (nonatomic, strong)NSArray *subTitles;
@property (nonatomic, strong)NSArray *images;
@end

static NSString *CellIdentifier = @"Cell";

@implementation CommonToolsViewController

- (id)init
{
    self = [super init];
    if (self) {
        // Custom initialization
        self.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"常用工具" image:nil tag:0];
        [[self tabBarItem] setFinishedSelectedImage:[UIImage imageNamed:@"tab_1_focus"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab_1"]];
        [[self tabBarItem] setTitleTextAttributes:@{UITextAttributeTextColor: [UIColor grayColor],
                                                    UITextAttributeFont:[UIFont systemFontOfSize:kTabBarFontSize]
                                                    } forState:UIControlStateNormal];
        [[self tabBarItem] setTitleTextAttributes:@{UITextAttributeTextColor: RGBCOLOR(0, 172, 246),
                                                    UITextAttributeFont:[UIFont systemFontOfSize:kTabBarFontSize]
                                                    } forState:UIControlStateSelected];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"常用工具";
    self.titles = @[@"购房能力评估器",@"首二套测试器",@"购房税费计算器",@"房贷计算器",@"提前还款计算器",@"剩余还款计算器"];
    self.subTitles = @[@"根据您的资金情况生成适合您的购房方案",@"1分钟测出自己买房算几套，利率是多少",@"轻松算出新房、二手房交易税费",@"全面支持商贷、公积金、组合贷月供计算",@"提供部分、全额提前还款计算",@"查询已还、未还金额，了解还款状况"];
    self.images = @[[UIImage imageNamed:@"cygj_1"],[UIImage imageNamed:@"cygj_2"],[UIImage imageNamed:@"cygj_3"],[UIImage imageNamed:@"cygj_4"],[UIImage imageNamed:@"cygj_5"],[UIImage imageNamed:@"cygj_6"]];
    NSInteger rowHeight = 61;
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, UI_APPFRAME_HEIGHT)];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.rowHeight = rowHeight;
    //IS_IPHONE_5 ? 76 : 61;
    self.tableView.scrollEnabled = YES;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerNib:[UINib nibWithNibName:@"ComToolCell" bundle:nil] forCellReuseIdentifier:CellIdentifier];
    [self.view addSubview:self.tableView];
    
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return self.titles.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ComToolCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    cell.mainLabel.text = self.titles[indexPath.row];
    cell.subLabel.text = self.subTitles[indexPath.row];
    cell.imgView.image = self.images[indexPath.row];
    // Configure the cell...
    return cell;
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/


#pragma mark - Table view delegate

// In a xib-based application, navigation from a table can be handled in -tableView:didSelectRowAtIndexPath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here, for example:
    // Create the next view controller.
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    switch (indexPath.row) {
        case 0:{
            self.hidesBottomBarWhenPushed = YES;
            EvaluateCalculatorViewController *housingVC = [[EvaluateCalculatorViewController alloc]init];
            [self.navigationController pushViewController:housingVC animated:YES];
            self.hidesBottomBarWhenPushed = NO;
            break;
        }
        case 1:{
            self.hidesBottomBarWhenPushed = YES;
            RealEstateQaViewController *realEstateQaiewController = [[RealEstateQaViewController alloc]init];
            [self.navigationController pushViewController:realEstateQaiewController animated:YES];
            self.hidesBottomBarWhenPushed = NO;
            break;
        }
        case 2:{
            self.hidesBottomBarWhenPushed = YES;
            TaxesCalculatorViewController *taxesVC = [[TaxesCalculatorViewController alloc]init];
            [self.navigationController pushViewController:taxesVC animated:YES];
            self.hidesBottomBarWhenPushed = NO;
            break;
        }
        case 3:{
            self.hidesBottomBarWhenPushed = YES;
            LoanCalculatorViewController *calculateVC = [[LoanCalculatorViewController alloc]init];
            [self.navigationController pushViewController:calculateVC animated:YES];
            self.hidesBottomBarWhenPushed = NO;
            break;
        }
        case 4:{
            self.hidesBottomBarWhenPushed = YES;
            PrepaymentCalculatorViewController *preVC = [[PrepaymentCalculatorViewController alloc]init];
            [self.navigationController pushViewController:preVC animated:YES];
            self.hidesBottomBarWhenPushed = NO;
            break;
        }
        case 5:{
            self.hidesBottomBarWhenPushed = YES;
            RemainPaymentCalculatorViewController *remVC = [[RemainPaymentCalculatorViewController alloc]init];
            [self.navigationController pushViewController:remVC animated:YES];
            self.hidesBottomBarWhenPushed = NO;
        }
        default:
            break;
    }

    // Pass the selected object to the new view controller.
    
    // Push the view controller.
    
}

@end
